package cn.gailvlun.gll.presentation.wish.drawer;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ogaclejapan.smarttablayout.SmartTabLayout;

import cn.gailvlun.gll.R;
import cn.gailvlun.gll.databinding.ActivityWishListBinding;
import cn.gailvlun.gll.databinding.TabWishListBinding;
import cn.gailvlun.gll.presentation.base.App;
import cn.gailvlun.gll.presentation.base.BaseActivity;
import cn.gailvlun.gll.widget.NavigationBarView;



public class WishListActivity extends BaseActivity {

    public static void openActivity(Context context) {
        Intent intent = new Intent(context, WishListActivity.class);
        context.startActivity(intent);
    }

    private ActivityWishListBinding mBinding;

    private WishListPagerAdapter mPagerAdapter;

    
    private String[] tabTitles = App.getInstance().getResources().getStringArray(R.array.wish_drawer_tab_title);

    @Override
    protected void initComponent() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_wish_list);

        mPagerAdapter = new WishListPagerAdapter(getSupportFragmentManager());
        mBinding.vp.setAdapter(mPagerAdapter);
        mBinding.vp.setOffscreenPageLimit(1);

        mBinding.stl.setCustomTabView(new SmartTabLayout.TabProvider() {
            @Override
            public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
                TabWishListBinding tabBinding = DataBindingUtil.inflate(getLayoutInflater(),
                        R.layout.tab_wish_list, container, false);
                tabBinding.tvTab.setText(tabTitles[position]);
                return tabBinding.getRoot();
            }
        });
        mBinding.stl.setViewPager(mBinding.vp);
        mBinding.vp.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                for (int i = 0; i < tabTitles.length; i++) {
                    View view = mBinding.stl.getTabAt(i);
                    TextView tv = view.findViewById(R.id.tv_tab);
                    if (i == position) {
                        tv.setTextColor(getResources().getColor(R.color.white));
                    } else {
                        tv.setTextColor(getResources().getColor(R.color.whiteTwo));
                    }
                }
            }
        });
    }

    @Override
    protected void createHandler() {
        mBinding.nbv.setOnBackListener(new NavigationBarView.OnBackListener() {
            @Override
            public void onBack(NavigationBarView nb) {
                onBackPressed();
            }
        });

    }

    @Override
    protected void loadData(@Nullable Bundle savedInstanceState) {


    }


}
